<?php

//Lấy ra tin
$db_news = new db_query('SELECT new_id,new_title,new_date,new_picture,new_teaser,new_detail,new_tags,new_relate,new_link,new_cat_id,cat_name
                        FROM news 
                        LEFT JOIN categories_multi
                        ON(cat_id = new_cat_id)
                        WHERE new_id = '.$iNews.'
                        LIMIT 1');
$news = mysql_fetch_assoc($db_news->result);
unset($db_news);
$nums = strpos($news['new_link'],':');
if($nums > 0){
    $url_news = $news['new_link'];
}else{
    $url_news = 'http://'.$news['new_link'];
}
$url_parse = parse_url($url_news);

//update view
$db_update_view = new db_execute('UPDATE news SET new_view = new_view + 1 WHERE new_id = '.$news['new_id']);

//Đưa ra tin có thể quan tâm
//$db_list_hot = new db_query('SELECT new_id,new_title,new_picture,new_teaser,new_cat_id
//                                FROM news 
//                                WHERE  new_cat_id = '.$iCat.' AND new_id != '.$news['new_id'].' AND new_active = 1
//                                ORDER BY new_id DESC 
//                                LIMIT 3');
//$list_hot = $db_list_hot->resultArray();
//unset($db_list_hot);
//
//Đưa ra tin mới nhất của cat
//$cache_list_new_id  = 'list_new_'.$iNews;
//$listnew_cache = cache_get($cache_list_new_id);
//if(empty($listnew_cache['cache_body'])){
//    $list_new = json_decode(base64_decode($listnew_cache['cache_body']), true);
//    if(empty($list_new)){
        $db_list_new  = new db_query('SELECT new_id,new_title,new_picture,new_cat_id
                                      FROM news 
                                      WHERE new_cat_id = '.$news['new_cat_id'].' AND new_id != '.$news['new_id'].' AND new_active = 1
                                      ORDER BY new_id DESC 
                                      LIMIT 10');
        $list_new = $db_list_new->resultArray();
        unset($db_list_new);
        //$cache_spider_body = base64_encode(json_encode($list_new));
//        cache_set($cache_list_new_id, $cache_spider_body,3*3600);
//   }
//}else{
//   $list_new = json_decode(base64_decode($listnew_cache['cache_body']),true);
//}

//Lấy ra tin mới nhất trong ngày
//$date = date('d-m-Y',time());
//$start =  strtotime($date);
//$end =  $start + 84600;
//$db_news_date = new db_query('SELECT new_id,new_title,new_picture,new_teaser,new_cat_id
//                             FROM news 
//                             WHERE new_active = 1 AND new_cat_id != '.$iCat.' AND new_date BETWEEN '.$start .' AND '.$end.'
//                             ORDER BY new_date DESC
//                             LIMIT 10');
//$news_date = $db_news_date->resultArray();
//unset($db_news_date);
//Đưa ra tin đọc nhiều nhất - cùng categories - cách thời điểm truy cập 6 tiếng (tin xem nhiều trong 6 tiếng vừa qua)
$time_view = time() - 86400;
//$cache_list_view_id  = 'list_view_'.$iNews;
//$listview_cache = cache_get($cache_list_view_id);
//if(empty($listview_cache['cache_body'])){
//    $list_view = json_decode(base64_decode($listview_cache['cache_body']), true);
//    if(empty($list_view)){
        $db_list_view = new db_query('SELECT new_id,new_title,new_picture, new_cat_id
                                      FROM news
                                      WHERE new_date >= '.$time_view.' AND new_cat_id = '.$news['new_cat_id'].' AND new_id != '.$news['new_id'].'  AND new_active = 1
                                      ORDER BY new_view DESC 
                                      LIMIT 10');
        $list_view = $db_list_view->resultArray();
        unset($db_list_view);
        //$cache_spider_body = base64_encode(json_encode($list_view));
//        cache_set($cache_list_view_id, $cache_spider_body,3*3600);
//   }
//}else{
//   $list_view = json_decode(base64_decode($listview_cache['cache_body']),true);
//}

//Lấy ra bình luận của tin
//$db_list_comments = new db_query('SELECT * FROM comments WHERE com_news_id = '.$iNews.' AND com_active = 1 LIMIT 5');
//$list_comments = $db_list_comments->resultArray();
//unset($db_list_comments);
//
?>